﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace WebChatApi.Common
{
    /// <summary>
    /// 
    /// </summary>
    public sealed class PerformenceUtil : Singleton<PerformenceUtil>
    {
        private static Random random = new Random();
        private static PerformanceCounter cpuUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total");

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="PerformenceUtil"/> class.
        /// </summary>
        public PerformenceUtil() { }

        #endregion

        /// <summary>
        /// Gets the CPU usage by percent.
        /// </summary>
        /// <returns></returns>
        public float GetCPUUsageByPercent()
        {
            cpuUsage.NextValue();
            Thread.Sleep(1000);

            return cpuUsage.NextValue();
        }
    }
}
